refactor(ios): extract connection form logic into ConnectionFormViewModel#1165
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
P1 #5 step 2 of 3: lift business logic out of
ConnectionFormView(652 LOC) into a newConnectionFormViewModel. The View drops to 392 LOC and now owns only UI state (file-picker flags, new-database alert flag, haptic triggers); the ViewModel owns form fields, validation, async operations, and persistence.What moves into the ViewModel:
name,type,host,port,username,password,database,sslEnabled,groupId,tagId,safeModeLevel, plus the 11 SSH fields andselectedFileURL/newDatabaseNameloadStoredCredentials(secureStore:)(replaces inline keychain reads in.task),testConnection(appState:secureStore:),save(appState:secureStore:) -> DatabaseConnection?returning the connection on success or nil withcredentialErrorsethandleSQLiteFilePicker(_:),handleSSHKeyFilePicker(_:),createNewDatabase(),clearSelectedFile()buildConnection(),copyToDocuments(_:),updateDefaultPort(),canSave,isEditingdidSetontypeto reset port and SQLite file selection, replacing the inline.onChange(of: type)KeyInputModeenum and theTestResultstruct move to the VM where they belongWhat stays in the View:
@State:viewModel,activeFilePicker,pendingFilePicker,showNewDatabaseAlert,hapticSuccess,hapticErroractiveFilePicker+pendingFilePickeris preserved on purpose:.fileImporterresetsactiveFilePickervia the dismissal binding before the result closure fires, so the result handler readspendingFilePickerinsteadviewModel.credentialError != nilvia a derivedBinding<Bool>(no parallel@Stateflag)Test plan
.dbextensionssh_), paste key contentDatabaseConnectionviaonSave, sheet dismissesloadStoredCredentialshydrates password / SSH password / passphrase from Keychain on.task